<?php
	include_once('Process.php');
	
class Scheduler{
	/*Verfahrens Member*/
	private $max_runtime = 0;
	private $time = 0;
	private $newP = false;
	private $currentProcesses = array();
	private $arrayP = array();
	
	public function RoundRobin($processHandler, $quantum){
		//TODO:
		$this->resteVerfahren($processHandler);
		
		while($this->time < $this->max_runtime){
			foreach($processHandler->getProcessAtArriveTime($this->time) as $newProcess){
				array_push($this->currentProcesses, $newProcess);
				$this->newP = true;
			}
			//-----Scheduling Schritt-------------------
			if(count($this->currentProcesses) > 0){
			
			}
			/*Processe die eine Laufzeit == 0 haben loeschen*/
			$this->currentProcesses = $this->cleanUpArray($this->currentProcesses, $this->time, $this->arrayP);
			
			/*-----Scheduling Schritt Ende -----*/
			$this->time++;
			$this->newP = false;
		}
		return $this->verfahrenEnde('RR', $this->arrayP, $processHandler);
	}
	
	public function FirstComeFirstServed($processHandler){
		$this->resteVerfahren($processHandler);
		
		while($this->time < $this->max_runtime){
			foreach($processHandler->getProcessAtArriveTime($this->time) as $newProcess){
				array_push($this->currentProcesses, $newProcess);
				$this->newP = true;
			}
			//-----Scheduling Schritt-------------------
			if(count($this->currentProcesses) > 0){
				$process = $this->get_process_with_shortest_arrive_time($this->currentProcesses);
				/*echo 'new: '.var_dump($this->newP) .'<br />';
				echo 'im array: '.var_dump($this->getIndex($process, $this->arrayP) == -1) .'<br />';*/
				if ($this->newP && ($this->getIndex($process, $this->arrayP) == -1)){
					echo 'new: <br />';
					/*Neuer Process wird integriert && wenn es einen alten gab wird der mit einem End Zeitpunkt versehen*/
					if (count($this->arrayP)> 0){
						$this->arrayP [count($this->arrayP)- 1]->setEndTime($this->time-1);
					}
					$process->setStartTime($this->time);
					$process->setRemainingRuntime ($process->getRemainingRuntime ()-1);
					array_push($this->arrayP ,$process);
				} else if(count($this->arrayP) > 0 && $this->arrayP [count($this->arrayP)- 1]->getRemainingRuntime ()> 0 &&($this->arrayP [count($this->arrayP)- 1] == $process || !$this->newP)){
					echo 'weiterfueren: <br />';
					/*Process wird weiter ausgeführt*/
						$this->arrayP [count($this->arrayP)- 1]->setRemainingRuntime ($this->arrayP [count($this->arrayP)- 1]->getRemainingRuntime ()-1);
				} else {
					echo 'clonen: <br />';
					/*Schonmal gelaufender Process wird erneut gestartet && der alten wird mit einem End Zeitpunkt versehen*/
					if (count($this->arrayP)> 0){
						$this->arrayP [count($this->arrayP)- 1]->setEndTime($this->time-1);
					}
					/*Process mit den Aktuellen Daten holen*/
					$process = $this->arrayP[$this->getIndex($process, $this->arrayP)];
					/*Alter Process löschen*/
					$this->currentProcesses = $this->deleteProcess($this->currentProcesses, $process);
					//Clone und Inizialesiere den Process
					$procesClone = $this->cloneProcess($process);
					/*Neuen Process einbinden in den ablauf*/
					array_push($this->currentProcesses ,$procesClone);
					array_push($this->arrayP ,$procesClone);
				}
				/*Processe die eine Laufzeit == 0 haben loeschen*/
				$this->cleanUpArray();
			}
			/*-----Scheduling Schritt Ende -----*/
			$this->time++;
			$this->newP = false;
		}
		return $this->verfahrenEnde('FCFS', $this->arrayP, $processHandler);
	}
	
	public function LastComeFirstServed($processHandler){
		$this->resteVerfahren($processHandler);
		
		while($this->time < $this->max_runtime){
			foreach($processHandler->getProcessAtArriveTime($this->time) as $newProcess){
				array_push($this->currentProcesses, $newProcess);
				$this->newP = true;
			}
			//-----Scheduling Schritt-------------------
			if(count($this->currentProcesses) > 0){
				$process = $this->get_process_with_longest_arrive_time($this->currentProcesses);
				/*echo 'new: '.var_dump($this->newP) .'<br />';
				echo 'im array: '.var_dump($this->getIndex($process, $this->arrayP) == -1) .'<br />';*/
				if ($this->newP && ($this->getIndex($process, $this->arrayP) == -1)){
					echo 'new: <br />';
					/*Neuer Process wird integriert && wenn es einen alten gab wird der mit einem End Zeitpunkt versehen*/
					if (count($this->arrayP)> 0){
						$this->arrayP [count($this->arrayP)- 1]->setEndTime($this->time-1);
					}
					$process->setStartTime($this->time);
					$process->setRemainingRuntime ($process->getRemainingRuntime ()-1);
					array_push($this->arrayP ,$process);
				} else if(count($this->arrayP) > 0 && $this->arrayP [count($this->arrayP)- 1]->getRemainingRuntime ()> 0 &&($this->arrayP [count($this->arrayP)- 1] == $process || !$this->newP)){
					echo 'weiterfueren: <br />';
					/*Process wird weiter ausgeführt*/
						$this->arrayP [count($this->arrayP)- 1]->setRemainingRuntime ($this->arrayP [count($this->arrayP)- 1]->getRemainingRuntime ()-1);
				} else {
					echo 'clonen: <br />';
					/*Schonmal gelaufender Process wird erneut gestartet && der alten wird mit einem End Zeitpunkt versehen*/
					if (count($this->arrayP)> 0){
						$this->arrayP [count($this->arrayP)- 1]->setEndTime($this->time-1);
					}
					/*Process mit den Aktuellen Daten holen*/
					$process = $this->arrayP[$this->getIndex($process, $this->arrayP)];
					/*Alter Process löschen*/
					$this->currentProcesses = $this->deleteProcess($this->currentProcesses, $process);
					//Clone und Inizialesiere den Process
					$procesClone = $this->cloneProcess($process);
					/*Neuen Process einbinden in den ablauf*/
					array_push($this->currentProcesses ,$procesClone);
					array_push($this->arrayP ,$procesClone);
				}
				/*Processe die eine Laufzeit == 0 haben loeschen*/
				$this->cleanUpArray();
			}
			/*echo var_dump($process) .'<br/>';
			echo var_dump($this->arrayP) .'<br />'*/;
			/*-----Scheduling Schritt Ende -----*/
			$this->time++;
			$this->newP = false;
		}
		return $this->verfahrenEnde('LCFS', $this->arrayP, $processHandler);
	}
	
	function ShortestJobFirst($processHandler){
		$this->resteVerfahren($processHandler);
		
		while($this->time < $this->max_runtime){
			foreach($processHandler->getProcessAtArriveTime($this->time) as $newProcess){
				array_push($this->currentProcesses, $newProcess);
				$this->newP = true;
			}
			//-----Scheduling Schritt-------------------
			if(count($this->currentProcesses) > 0){
				$process = $this->get_process_with_shortest_runing_time($this->currentProcesses);
				echo 'new: '.var_dump($this->newP) .'<br />';
				echo 'im array: '.var_dump($this->getIndex($process, $this->arrayP) == -1) .'<br />';
				if (count($this->arrayP)> 0){
					echo 'last 0: '.var_dump($this->arrayP[count($this->arrayP)-1]->getRemainingRuntime() == 0) .'<br />';
				}
				if ($this->newP && ($this->getIndex($process, $this->arrayP) == -1)||$this->arrayP[count($this->arrayP)-1]->getRemainingRuntime() == 0 && ($this->getIndex($process, $this->arrayP) == -1)){
					echo 'new: <br />';
					/*Neuer Process wird integriert && wenn es einen alten gab wird der mit einem End Zeitpunkt versehen*/
					if (count($this->arrayP)> 0){
						$this->arrayP [count($this->arrayP)- 1]->setEndTime($this->time-1);
					}
					$process->setStartTime($this->time);
					$process->setRemainingRuntime ($process->getRemainingRuntime ()-1);
					array_push($this->arrayP ,$process);
				} else if(count($this->arrayP) > 0 && $this->arrayP [count($this->arrayP)- 1]->getRemainingRuntime ()> 0 &&($this->arrayP [count($this->arrayP)- 1] == $process || !$this->newP)){
					echo 'weiterfueren: <br />';
					/*Process wird weiter ausgeführt*/
						$this->arrayP [count($this->arrayP)- 1]->setRemainingRuntime ($this->arrayP [count($this->arrayP)- 1]->getRemainingRuntime ()-1);
				} else {
					echo 'clonen: '.var_dump($process) .'<br />';
					foreach ($this->arrayP as $value){
						echo var_dump($value) .'<br />';
					}
					/*Schonmal gelaufender Process wird erneut gestartet && der alten wird mit einem End Zeitpunkt versehen*/
					if (count($this->arrayP)> 0){
						$this->arrayP [count($this->arrayP)- 1]->setEndTime($this->time-1);
					}
					/*Process mit den Aktuellen Daten holen*/
					$process = $this->arrayP[$this->getIndex($process, $this->arrayP)];
					/*Alter Process löschen*/
					$this->currentProcesses = $this->deleteProcess($this->currentProcesses, $process);
					//Clone und Inizialesiere den Process
					$procesClone = $this->cloneProcess($process);
					/*Neuen Process einbinden in den ablauf*/
					array_push($this->currentProcesses ,$procesClone);
					array_push($this->arrayP ,$procesClone);
				}
				/*Processe die eine Laufzeit == 0 haben loeschen*/
				$this->cleanUpArray();
			}
			/*-----Scheduling Schritt Ende -----*/
			$this->time++;
			$this->newP = false;
		}
		return $this->verfahrenEnde('SJF', $this->arrayP, $processHandler);
	}
	
	function LongestJobFirst($processHandler){
		$this->resteVerfahren($processHandler);
		
		while($this->time < $this->max_runtime){
			foreach($processHandler->getProcessAtArriveTime($this->time) as $newProcess){
				array_push($this->currentProcesses, $newProcess);
				$this->newP = true;
			}
			//-----Scheduling Schritt-------------------
			if(count($this->currentProcesses) > 0){
				$process = $this->get_process_with_longest_runing_time($this->currentProcesses);
				/*echo 'new: '.var_dump($this->newP) .'<br />';
				echo 'im array: '.var_dump($this->getIndex($process, $this->arrayP) == -1) .'<br />';*/
				if ($this->newP && ($this->getIndex($process, $this->arrayP) == -1)){
					echo 'new: <br />';
					/*Neuer Process wird integriert && wenn es einen alten gab wird der mit einem End Zeitpunkt versehen*/
					if (count($this->arrayP)> 0){
						$this->arrayP [count($this->arrayP)- 1]->setEndTime($this->time-1);
					}
					$process->setStartTime($this->time);
					$process->setRemainingRuntime ($process->getRemainingRuntime ()-1);
					array_push($this->arrayP ,$process);
				} else if(count($this->arrayP) > 0 && $this->arrayP [count($this->arrayP)- 1]->getRemainingRuntime ()> 0 &&($this->arrayP [count($this->arrayP)- 1] == $process || !$this->newP)){
					echo 'weiterfueren: <br />';
					/*Process wird weiter ausgeführt*/
						$this->arrayP [count($this->arrayP)- 1]->setRemainingRuntime ($this->arrayP [count($this->arrayP)- 1]->getRemainingRuntime ()-1);
				} else {
					echo 'clonen: <br />';
					/*Schonmal gelaufender Process wird erneut gestartet && der alten wird mit einem End Zeitpunkt versehen*/
					if (count($this->arrayP)> 0){
						$this->arrayP [count($this->arrayP)- 1]->setEndTime($this->time-1);
					}
					/*Process mit den Aktuellen Daten holen*/
					$process = $this->arrayP[$this->getIndex($process, $this->arrayP)];
					/*Alter Process löschen*/
					$this->currentProcesses = $this->deleteProcess($this->currentProcesses, $process);
					//Clone und Inizialesiere den Process
					$procesClone = $this->cloneProcess($process);
					/*Neuen Process einbinden in den ablauf*/
					array_push($this->currentProcesses ,$procesClone);
					array_push($this->arrayP ,$procesClone);
				}
				/*Processe die eine Laufzeit == 0 haben loeschen*/
				$this->cleanUpArray();
			}
			/*-----Scheduling Schritt Ende -----*/
			$this->time++;
			$this->newP = false;
		}
		
		return $this->verfahrenEnde('LJF', $this->arrayP, $processHandler);
	}
	
	function LongestRemainingTimeFirst($processHandler){
		$this->resteVerfahren($processHandler);
		
		while($this->time < $this->max_runtime){
			foreach($processHandler->getProcessAtArriveTime($this->time) as $newProcess){
				array_push($this->currentProcesses, $newProcess);
				$this->newP = true;
			}
			//-----Scheduling Schritt-------------------
			if(count($this->currentProcesses) > 0){
				$process = $this->get_process_with_longest_remaining_time($this->currentProcesses);
				/*echo 'new: '.var_dump($this->newP) .'<br />';
				echo 'im array: '.var_dump($this->getIndex($process, $this->arrayP) == -1) .'<br />';*/
				if ($this->newP && ($this->getIndex($process, $this->arrayP) == -1)){
					echo 'new: <br />';
					/*Neuer Process wird integriert && wenn es einen alten gab wird der mit einem End Zeitpunkt versehen*/
					if (count($this->arrayP)> 0){
						$this->arrayP [count($this->arrayP)- 1]->setEndTime($this->time-1);
					}
					$process->setStartTime($this->time);
					$process->setRemainingRuntime ($process->getRemainingRuntime ()-1);
					array_push($this->arrayP ,$process);
				} else if(count($this->arrayP) > 0 && $this->arrayP [count($this->arrayP)- 1]->getRemainingRuntime ()> 0 &&($this->arrayP [count($this->arrayP)- 1] == $process || !$this->newP)){
					echo 'weiterfueren: <br />';
					/*Process wird weiter ausgeführt*/
						$this->arrayP [count($this->arrayP)- 1]->setRemainingRuntime ($this->arrayP [count($this->arrayP)- 1]->getRemainingRuntime ()-1);
				} else {
					echo 'clonen: <br />';
					/*Schonmal gelaufender Process wird erneut gestartet && der alten wird mit einem End Zeitpunkt versehen*/
					if (count($this->arrayP)> 0){
						$this->arrayP [count($this->arrayP)- 1]->setEndTime($this->time-1);
					}
					/*Process mit den Aktuellen Daten holen*/
					$process = $this->arrayP[$this->getIndex($process, $this->arrayP)];
					/*Alter Process löschen*/
					$this->currentProcesses = $this->deleteProcess($this->currentProcesses, $process);
					//Clone und Inizialesiere den Process
					$procesClone = $this->cloneProcess($process);
					/*Neuen Process einbinden in den ablauf*/
					array_push($this->currentProcesses ,$procesClone);
					array_push($this->arrayP ,$procesClone);
				}
				/*Processe die eine Laufzeit == 0 haben loeschen*/
				$this->cleanUpArray();
			}
			/*-----Scheduling Schritt Ende -----*/
			$this->time++;
			$this->newP = false;
		}
		return $this->verfahrenEnde('LRTF', $this->arrayP, $processHandler);
	}
	
	function ShortestRemainingTimeFirst($processHandler){
		$this->resteVerfahren($processHandler);
		
		while($this->time < $this->max_runtime){
			foreach($processHandler->getProcessAtArriveTime($this->time) as $newProcess){
				array_push($this->currentProcesses, $newProcess);
				$this->newP = true;
			}
			//-----Scheduling Schritt-------------------
			if(count($this->currentProcesses) > 0){
				$process = $this->get_process_with_shortest_remaining_time($this->currentProcesses);
				/*echo 'new: '.var_dump($this->newP) .'<br />';
				echo 'im array: '.var_dump($this->getIndex($process, $this->arrayP) == -1) .'<br />';*/
				if ($this->newP && ($this->getIndex($process, $this->arrayP) == -1)){
					echo 'new: <br />';
					/*Neuer Process wird integriert && wenn es einen alten gab wird der mit einem End Zeitpunkt versehen*/
					if (count($this->arrayP)> 0){
						$this->arrayP [count($this->arrayP)- 1]->setEndTime($this->time-1);
					}
					$process->setStartTime($this->time);
					$process->setRemainingRuntime ($process->getRemainingRuntime ()-1);
					array_push($this->arrayP ,$process);
				} else if(count($this->arrayP) > 0 && $this->arrayP [count($this->arrayP)- 1]->getRemainingRuntime ()> 0 &&($this->arrayP [count($this->arrayP)- 1] == $process || !$this->newP)){
					echo 'weiterfueren: <br />';
					/*Process wird weiter ausgeführt*/
						$this->arrayP [count($this->arrayP)- 1]->setRemainingRuntime ($this->arrayP [count($this->arrayP)- 1]->getRemainingRuntime ()-1);
				} else {
					echo 'clonen: <br />';
					/*Schonmal gelaufender Process wird erneut gestartet && der alten wird mit einem End Zeitpunkt versehen*/
					if (count($this->arrayP)> 0){
						$this->arrayP [count($this->arrayP)- 1]->setEndTime($this->time-1);
					}
					/*Process mit den Aktuellen Daten holen*/
					$process = $this->arrayP[$this->getIndex($process, $this->arrayP)];
					/*Alter Process löschen*/
					$this->currentProcesses = $this->deleteProcess($this->currentProcesses, $process);
					//Clone und Inizialesiere den Process
					$procesClone = $this->cloneProcess($process);
					/*Neuen Process einbinden in den ablauf*/
					array_push($this->currentProcesses ,$procesClone);
					array_push($this->arrayP ,$procesClone);
				}
				/*Processe die eine Laufzeit == 0 haben loeschen*/
				$this->cleanUpArray();
			}
			/*-----Scheduling Schritt Ende -----*/
			$this->time++;
			$this->newP = false;
		}
		return $this->verfahrenEnde('SRTF', $this->arrayP, $processHandler);
	}
	
	function PrioritaetengesteuertesScheduling($processHandler){
		$this->resteVerfahren($processHandler);
		
		while($this->time < $this->max_runtime){
			foreach($processHandler->getProcessAtArriveTime($this->time) as $newProcess){
				array_push($this->currentProcesses, $newProcess);
				$this->newP = true;
			}
			//-----Scheduling Schritt-------------------
			if(count($this->currentProcesses) > 0){
				$process = $this->get_process_with_highest_priority($this->currentProcesses);
				/*echo 'new: '.var_dump($this->newP) .'<br />';
				echo 'im array: '.var_dump($this->getIndex($process, $this->arrayP) == -1) .'<br />';*/
				if ($this->newP && ($this->getIndex($process, $this->arrayP) == -1)){
					echo 'new: <br />';
					/*Neuer Process wird integriert && wenn es einen alten gab wird der mit einem End Zeitpunkt versehen*/
					if (count($this->arrayP)> 0){
						$this->arrayP [count($this->arrayP)- 1]->setEndTime($this->time-1);
					}
					$process->setStartTime($this->time);
					$process->setRemainingRuntime ($process->getRemainingRuntime ()-1);
					array_push($this->arrayP ,$process);
				} else if(count($this->arrayP) > 0 && $this->arrayP [count($this->arrayP)- 1]->getRemainingRuntime ()> 0 &&($this->arrayP [count($this->arrayP)- 1] == $process || !$this->newP)){
					echo 'weiterfueren: <br />';
					/*Process wird weiter ausgeführt*/
						$this->arrayP [count($this->arrayP)- 1]->setRemainingRuntime ($this->arrayP [count($this->arrayP)- 1]->getRemainingRuntime ()-1);
				} else {
					echo 'clonen: <br />';
					/*Schonmal gelaufender Process wird erneut gestartet && der alten wird mit einem End Zeitpunkt versehen*/
					if (count($this->arrayP)> 0){
						$this->arrayP [count($this->arrayP)- 1]->setEndTime($this->time-1);
					}
					/*Process mit den Aktuellen Daten holen*/
					$process = $this->arrayP[$this->getIndex($process, $this->arrayP)];
					/*Alter Process löschen*/
					$this->currentProcesses = $this->deleteProcess($this->currentProcesses, $process);
					//Clone und Inizialesiere den Process
					$procesClone = $this->cloneProcess($process);
					/*Neuen Process einbinden in den ablauf*/
					array_push($this->currentProcesses ,$procesClone);
					array_push($this->arrayP ,$procesClone);
				}
				/*Processe die eine Laufzeit == 0 haben loeschen*/
				$this->cleanUpArray();
			}
			/*-----Scheduling Schritt Ende -----*/
			$this->time++;
			$this->newP = false;
		}
		return $this->verfahrenEnde('PS', $this->arrayP, $processHandler);
	}
	
	//Gibt den Process mit der Laengsten CPU-Restlaufzeit zurueck
	private function get_process_with_longest_remaining_time($processes) {		
		$currentMax = 0;
		$result;
		foreach ($processes as $value) {
			if($value->getRemainingRuntime () > $currentMax && $value->getRemainingRuntime () != 0) {
				$result = $value;
				$currentMax = $value->getRemainingRuntime ();
			} else if ($value->getRemainingRuntime () == 0){
				$result = $value;
			}
		}
		return $result;
	}
	
	//Gibt den Process mit der hoechsten Prioritaet zurueck
	private function get_process_with_highest_priority($processes) {		
		$currentMax = 0;
		foreach ($processes as $value) {
			if($value->getPriority () > $currentMax) {
				$result = $value;
				$currentMax = $value->getPriority ();
			}
		}
		return $result;
	}
	
	//Gibt den Process mit der Kuerzesten CPU-Restlaufzeit zurueck
	private function get_process_with_shortest_remaining_time($processes) {		
		$currentMin = 501;
		foreach ($processes as $value) {
			if($value->getRemainingRuntime () < $currentMin) {
				$result = $value;
				$currentMin = $value->getRemainingRuntime ();
			}
		}
		return $result;
	}
	
	//Gibt den Process mit der Kuerzesten Ankunftszeit zurueck
	private function get_process_with_shortest_arrive_time($processes) {		
		$currentMin = 101;
		foreach ($processes as $value) {
			if($value->getArrive () < $currentMin) {
				$result = $value;
				$currentMin = $value->getArrive ();
			}
		}
		return $result;
	}
	
	//Gibt den Process mit der Laengsten Ankunftszeit zurueck
	private function get_process_with_longest_arrive_time($processes) {		
		$currentMax = -1;
		foreach ($processes as $value) {
			if($value->getArrive () > $currentMax) {
				$result = $value;
				$currentMax = $value->getArrive ();
			}
		}
		return $result;
	}
	
	//Gibt den Process mit der Kuerzesten CPU-Laufzeit zurueck
	private function get_process_with_shortest_runing_time($processes) {		
		$currentMin = 501;
		foreach ($processes as $value) {
			if($value->getRuntime () < $currentMin) {
				$result = $value;
				$currentMin = $value->getRuntime ();
			}
		}
		return $result;
	}
	
	//Gibt den Process mit der Laengsten CPU-Laufzeit zurueck
	private function get_process_with_longest_runing_time($processes) {		
		$currentMax = 0;
		foreach ($processes as $value) {
			if($value->getRuntime () > $currentMax) {
				$result = $value;
				$currentMax = $value->getRuntime ();
			}
		}
		return $result;
	}
	
	/*Sucht den Index des übergebenen Objektes in dem Array*/
	private function getIndex ($process, $array){
		if (count($array)){
			for($counter = 0; $counter < count($array);$counter++){
				if ($array[$counter] == $process){
					return $counter;
				}
			}
		}
		return -1;
	}
	
	/*Gibt ein Array mit allen derzeit schon angekommenen Processen zurueck*/
	function getCurrentProcesses ($time, $processes){
		$array = array ();
		foreach($processes as $value){
			if ($value->getArrive ()<= $time){
				array_push($array, $value);
			}
		}
		return $array;
	}
	
	/*Entfernt alle Processe aus dem Array die eine Restlaufzeit von 0 ms haben*/
	private function cleanUpArray (){
		foreach($this->currentProcesses as $value){		
			if ($value->getRemainingRuntime () ==  0){
				$this->arrayP[$this->getIndex($value, $this->arrayP)]->setEndTime($this->time);
				$this->currentProcesses = $this->deleteProcess($this->currentProcesses, $value);
			}
		}
	}
	
	/*Inizialesiert einen Process der die CPU zugewisen bekommt*/
	private function startProcess ($process, $time){
		$process->setStartTime($time);
		$process->setRemainingRuntime ($process->getRemainingRuntime ()-1);
		return $process;	
	}
	
	/*Clont und inizialesiert einen Process*/
	private function cloneProcess ($process){
		$procesClone = clone $process;
		$procesClone->setStartTime($this->time);
		$procesClone->setRemainingRuntime ($process->getRemainingRuntime ()-1);
		return $procesClone;
	}
	
	/*Loescht einen Process sicher aus dem Array*/
	private function deleteProcess ($array, $process){
		unset($array[$this->getIndex($process, $array)]);
	  	return array_values($array);
	}
	
	/*Setzt den Namen und das Array wieder in dem Handler*/
	private function verfahrenEnde ($name, $array, $processHandler){
		$processHandler->setVerfahren($name);
		$processHandler->setProcessArray($array);
		return $processHandler;
	}
	
	/*Setzt die Member zurueck um ein neues Verfahren zu starten*/
	private function resteVerfahren ($processHandler){
		$this->max_runtime = $processHandler->getRuningTime() + $processHandler->getArriveTimeHigh () +1;
		$this->time = 0;
		$this->newP = false;
		$this->currentProcesses = array();
		$this->arrayP = array();
	}
}
?>